package com.newcapec.erp.ui;

import com.newcapec.erp.bean.UserEntity;
import com.newcapec.erp.main.DataInit;
import com.newcapec.erp.utils.XMLFReader;
import com.newcapec.erp.utils.XMLFWriter;

import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;

public class UpdateUserUI extends JFrame {

	private JPanel contentPane;
	private JLabel label;
	private JLabel label_1;
	private JLabel label_2;
	private JLabel label_3;
	private JLabel label_4;
	private JLabel label_5;
	private JTextField textField;
	private JTextField textField_1;
	private JTextField textField_2;
	private JTextField textField_3;
	private JTextField textField_4;
	private JTextField textField_5;
	private UserEntity systemEntity;
	private int index;
	private int currentPage;

public UpdateUserUI(){}
	/**
	 * Create the frame.
	 */
	public UpdateUserUI(UserEntity systemEntity, int index, int currentPage) {
		this.systemEntity = systemEntity;
		this.index = index;
		this.currentPage = currentPage;
		setIconImage(Toolkit.getDefaultToolkit().getImage("images/logo.png"));
		setTitle("修改用户信息");
		setBounds(100, 100, 452, 568);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);

		label = new JLabel(DataInit.warehouseColumnNames.get(0));
		label.setBounds(20,34,100,37);
		textField = new JTextField();
		textField.setBounds(80, 34, 341, 37);
		textField.setText(systemEntity.getUserAn());
		textField.setColumns(10);
		contentPane.add(label);
		contentPane.add(textField);

		label_1 = new JLabel(DataInit.systemColumnNames.get(1));
		label_1.setBounds(20,107,100,37);
		textField_1 = new JTextField();
		textField_1.setColumns(10);
		textField_1.setBounds(80, 107, 341, 37);
		textField_1.setText(systemEntity.getUserName());
		contentPane.add(label_1);
		contentPane.add(textField_1);

		label_2 = new JLabel(DataInit.systemColumnNames.get(2));
		label_2.setBounds(20,185,100,37);
		textField_2 = new JTextField();
		textField_2.setColumns(10);
		textField_2.setBounds(80, 185, 341, 37);
		textField_2.setText(systemEntity.getUserOrganize());
		contentPane.add(label_2);
		contentPane.add(textField_2);

		label_3 = new JLabel(DataInit.systemColumnNames.get(3));
		label_3.setBounds(20,254,100,37);
		textField_3 = new JTextField();
		textField_3.setColumns(10);
		textField_3.setBounds(80, 254, 341, 37);
		textField_3.setText(systemEntity.getUserRole());
		contentPane.add(label_3);
		contentPane.add(textField_3);

		label_4 = new JLabel(DataInit.systemColumnNames.get(4));
		label_4.setBounds(20,328,100,37);
		textField_4 = new JTextField();
		textField_4.setColumns(10);
		textField_4.setBounds(80, 328, 341, 37);
		textField_4.setText(systemEntity.getCreateTime());
		contentPane.add(label_4);
		contentPane.add(textField_4);

		label_5 = new JLabel(DataInit.systemColumnNames.get(5));
		label_5.setBounds(20,402,100,37);
		textField_5 = new JTextField();
		textField_5.setColumns(10);
		textField_5.setBounds(80, 402, 341, 37);
		textField_5.setText(systemEntity.getUserState());
		contentPane.add(label_5);
		contentPane.add(textField_5);

		JButton button = new JButton("保存");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				String text = textField.getText();
				String text1 = textField_1.getText();
				String text2 = textField_2.getText();
				String text3 = textField_3.getText();
				String text4 = textField_4.getText();
				String text5 = textField_5.getText();
				UserEntity newSystemEntity = new UserEntity(text, text1, text2, text3, text4, text5);
				XMLFWriter.UpdateSystem(index,newSystemEntity);
				JOptionPane.showMessageDialog(null, "恭喜你，修改成功.", "提示",JOptionPane.PLAIN_MESSAGE);
				Vector<Vector<String>> data = XMLFReader.getData(DataInit.TYPE_SYSTEM);
				MainUI.updateMainUI(DataInit.TYPE_SYSTEM,data,currentPage);
				dispose();
			}
		});
		button.setBounds(221, 481, 93, 23);
		contentPane.add(button);
		setLocationRelativeTo(null);
		setVisible(true);

	}

}

